﻿function onresize_pnLeftBar() {
    if ($get(g_str_pnLeftMenu) == null || $get(g_str_pnContent) == null)
        return;

    $get(g_str_pnLeftMenu).style.width = (($get(g_str_pnLeftMenu).clientHeight < $get(g_str_pnLeftMenu).scrollHeight) ? 190 : 174) + 'px';
    if ($get(g_str_imgPin).src.indexOf("pin_off") == -1) {
        if (!g_bIE6)
            $get(g_str_pnContent).style.left = (($get(g_str_pnLeftMenu).clientHeight <= $get(g_str_pnLeftMenu).scrollHeight) ? 190 : 174) + 'px';
        else
            $get(g_str_pnContent).style.borderLeftWidth = (($get(g_str_pnLeftMenu).clientHeight <= $get(g_str_pnLeftMenu).scrollHeight) ? 190 : 174) + 'px';
    }
}

function onclick_imgPin() {
	if ($get(g_str_pnLeftMenu) == null || $get(g_str_imgPin) == null || $get(g_str_pnContent) == null)
        return;

    if ($get(g_str_imgPin).src.indexOf("pin_off") != -1) {
        $get(g_str_imgPin).src = $get(g_str_imgPin).src.replace("pin_off", "pin_on");
        if (!g_bIE6)
            $get(g_str_pnContent).style.left = (($get(g_str_pnLeftMenu).clientHeight <= $get(g_str_pnLeftMenu).scrollHeight) ? 190 : 174) + 'px';
        else
            $get(g_str_pnContent).style.borderLeftWidth = (($get(g_str_pnLeftMenu).clientHeight <= $get(g_str_pnLeftMenu).scrollHeight) ? 190 : 174) + 'px';
        document.cookie = "MenuPin=true; path=/; expires=Fri, 31 Dec 2021 23:59:59 GMT;";
    }
    else {
        $get(g_str_imgPin).src = $get(g_str_imgPin).src.replace("pin_on", "pin_off");
        if (!g_bIE6)
            $get(g_str_pnContent).style.left = '20px';
        else
            $get(g_str_pnContent).style.borderLeftWidth = '20px';
        document.cookie = "MenuPin=false; path=/; expires=Fri, 31 Dec 2021 23:59:59 GMT;";
    }
}

var iHideHandler;
function onmouseover_pnLeftMenu(e, t) {
    clearTimeout(iHideHandler);
}

var overrideGenericHandler = false;
function onmousedown_pnLeftBar(e, t) {
	overrideGenericHandler = true;
	if ($get(g_str_pnLeftMenu) == null || $get(g_str_pnHeadBG2) == null || $get(g_str_imgPin) == null)
        return;

    clearTimeout(iHideHandler);

    $get(g_str_pnHeadBG2).style.backgroundImage = "url(" + g_str_ApplicationPath + "/Images/top_hipo_on.gif)";
    $get(g_str_pnLeftMenu).style.left = '0px';
    $get(g_str_imgPin).style.display = '';
}

function hide_pnLeftMenu(fromGenericHandler) {
	if (fromGenericHandler && overrideGenericHandler) {
		overrideGenericHandler = false;
		return;
	}
    if ($get(g_str_imgPin).src.indexOf("pin_off") != -1) {
        if ($get(g_str_pnLeftMenu) == null || $get(g_str_pnHeadBG2) == null || $get(g_str_imgPin) == null)
            return;

        $get(g_str_pnHeadBG2).style.backgroundImage = "url(" + g_str_ApplicationPath + "/Images/top_hipo_off.gif)";
        $get(g_str_pnLeftMenu).style.left = '-190px';
        $get(g_str_imgPin).style.display = 'none';
    }
}

function timed_hide_pnLeftMenu() {
	hide_pnLeftMenu(false);
}

function onmouseout_pnLeftMenu(e, t) 
{
	//alert("out");
    if ($get(g_str_imgPin) == null)
        return;

    if ($get(g_str_imgPin).src.indexOf("pin_off") != -1) 
    {
        if (!e) 
            e = window.event;

        var t1 = e.toElement;
        if (!t1)
            t1 = e.explicitOriginalTarget;

        if (t && t1) 
        {
            var b = false;
            if (t.contains)
                b = t.contains(t1);
            else
                b = ElementContains(t, t1);

            if (b || t1 == $get(g_str_imgPin)) {
                return false;
            }
                
        }

        iHideHandler = setTimeout("timed_hide_pnLeftMenu()", 700);
    }
}

function ElementContains(p, c) {
	if (typeof (c) == 'string')
        c = document.getElementById(c);
    if (!c)
        return false;

    if (c.parentNode === p)
        return true;
    if (c === document.body)
        return false;
    return ElementContains(p, c.parentNode);
}
